//
// Created by 39442 on 2025/10/4.
//

#ifndef THREAD_POOL_RESULT_H
#define THREAD_POOL_RESULT_H

#include "Any.h"
#include "Semaphore.h"
class Task;
class Result
{
public:
    explicit Result(std::shared_ptr<Task> task, bool isValid = true);
    ~Result() = default;

    //setVal方法，获取任务执行完的返回值
    void setVal(Any any);

    //用户调用此方法获取task的返回值
    Any get();
private:
    Any any_;	//储存返回值
    Semaphore sem_;	//信号量
    std::shared_ptr<Task> task_;	//指向对应获取返回值的任务对象
    std::atomic_bool isValid_;	//返回值是否有效
};

#endif //THREAD_POOL_RESULT_H